home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Microsoft Visual Basic .NET
/
Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin
/
17 controls
/
databindingdemo
/
adonetbindingform.vb
< prev
next >
Wrap
Text File
|
2002-03-16
|
8KB
|
219 lines
Imports System.Data
Imports System.Data.OleDb
Public Class AdoNetBindingForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents btnFirst As System.Windows.Forms.Button
Friend WithEvents lblRecord As System.Windows.Forms.Label
Friend WithEvents btnNext As System.Windows.Forms.Button
Friend WithEvents btnLast As System.Windows.Forms.Button
Friend WithEvents btnPrevious As System.Windows.Forms.Button
Friend WithEvents txtName As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtState As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents txtCity As System.Windows.Forms.TextBox
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnLast = New System.Windows.Forms.Button()
Me.txtCity = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.btnPrevious = New System.Windows.Forms.Button()
Me.Label3 = New System.Windows.Forms.Label()
Me.btnFirst = New System.Windows.Forms.Button()
Me.btnNext = New System.Windows.Forms.Button()
Me.txtState = New System.Windows.Forms.TextBox()
Me.lblRecord = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.txtName = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'btnLast
'
Me.btnLast.Location = New System.Drawing.Point(336, 88)
Me.btnLast.Name = "btnLast"
Me.btnLast.Size = New System.Drawing.Size(48, 32)
Me.btnLast.TabIndex = 11
Me.btnLast.Text = ">>"
'
'txtCity
'
Me.txtCity.Location = New System.Drawing.Point(208, 40)
Me.txtCity.Name = "txtCity"
Me.txtCity.Size = New System.Drawing.Size(160, 24)
Me.txtCity.TabIndex = 0
Me.txtCity.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(152, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Name"
'
'btnPrevious
'
Me.btnPrevious.Location = New System.Drawing.Point(152, 88)
Me.btnPrevious.Name = "btnPrevious"
Me.btnPrevious.Size = New System.Drawing.Size(48, 32)
Me.btnPrevious.TabIndex = 8
Me.btnPrevious.Text = "<"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(208, 16)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(152, 16)
Me.Label3.TabIndex = 1
Me.Label3.Text = "City"
'
'btnFirst
'
Me.btnFirst.Location = New System.Drawing.Point(104, 88)
Me.btnFirst.Name = "btnFirst"
Me.btnFirst.Size = New System.Drawing.Size(48, 32)
Me.btnFirst.TabIndex = 7
Me.btnFirst.Text = "<<"
'
'btnNext
'
Me.btnNext.Location = New System.Drawing.Point(288, 88)
Me.btnNext.Name = "btnNext"
Me.btnNext.Size = New System.Drawing.Size(48, 32)
Me.btnNext.TabIndex = 10
Me.btnNext.Text = ">"
'
'txtState
'
Me.txtState.Location = New System.Drawing.Point(376, 40)
Me.txtState.Name = "txtState"
Me.txtState.Size = New System.Drawing.Size(96, 24)
Me.txtState.TabIndex = 0
Me.txtState.Text = ""
'
'lblRecord
'
Me.lblRecord.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.lblRecord.Location = New System.Drawing.Point(200, 88)
Me.lblRecord.Name = "lblRecord"
Me.lblRecord.Size = New System.Drawing.Size(88, 32)
Me.lblRecord.TabIndex = 9
Me.lblRecord.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(376, 16)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 16)
Me.Label2.TabIndex = 1
Me.Label2.Text = "State"
'
'txtName
'
Me.txtName.Location = New System.Drawing.Point(24, 40)
Me.txtName.Name = "txtName"
Me.txtName.Size = New System.Drawing.Size(168, 24)
Me.txtName.TabIndex = 0
Me.txtName.Text = ""
'
'AdoNetBindingForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
Me.ClientSize = New System.Drawing.Size(496, 149)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.txtCity, Me.Label2, Me.txtState, Me.btnFirst, Me.lblRecord, Me.btnNext, Me.btnLast, Me.btnPrevious, Me.Label1, Me.txtName})
Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "AdoNetBindingForm"
Me.Text = "AdoNetBindingForm"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub AdoNetBindingForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateDataSet()
InitializeBinding()
End Sub
Dim dsBiblio As New DataSet()
Dim bmb As BindingManagerBase
' creates a DataSet containing the Publishers table
Sub CreateDataSet()
' Open a connection to the Biblio.mdb database.
' (You might have to provide a different connection string or path.)
Dim cn As New OleDbConnection(BiblioConnString)
cn.Open()
' Create a data adapter on this connection.
Dim daPublishers As New OleDbDataAdapter("SELECT * FROM Publishers", cn)
' Fill the DataSet object with data from the Publishers table.
daPublishers.Fill(dsBiblio, "Publishers")
' Close the connection.
cn.Close()
End Sub
' initialize all fields for data binding
Sub InitializeBinding()
' Bind fields to database fields.
txtName.DataBindings.Add("Text", dsBiblio, "Publishers.Name")
txtCity.DataBindings.Add("Text", dsBiblio, "Publishers.City")
txtState.DataBindings.Add("Text", dsBiblio, "Publishers.State")
' get a reference to the BindingManagerBase object.
bmb = Me.BindingContext(dsBiblio, "Publishers")
' Force a refresh.
bmb.Position = bmb.Count
bmb.Position = 0
End Sub
' navigational buttons
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
bmb.Position = 0
End Sub
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
bmb.Position -= 1
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
bmb.Position += 1
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
bmb.Position = bmb.Count
End Sub
End Class